package com.hougong.im.transport;

import com.hougong.im.utils.NumberUtils;
import com.hougong.im.utils.StringUtils;

import java.io.Serializable;
import java.util.Arrays;

/**
 * 起始位	包长度	消息流水号	协议版本	   消息类型	业务类型	数据区	校验码
 * 1字节	    4字节	4字节	    1字节      	1字节	2字节	N	    1字节
 */
public class BaseFrame implements Serializable {
    public static final int BASE_LENGTH=1+4+4+1+1+2+1;
    public static byte START_FLAG=0X6C;
    public static byte VERSION=0X01;
    private byte start;
    private int length;
    private int streamId;
    private byte version;
    private byte messageType;
    private short bizType;
    private byte[] body;
    private byte check;

    public byte getStart() {
        return start;
    }

    public void setStart(byte start) {
        this.start = start;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getStreamId() {
        return streamId;
    }

    public void setStreamId(int streamId) {
        this.streamId = streamId;
    }

    public byte getVersion() {
        return version;
    }

    public void setVersion(byte version) {
        this.version = version;
    }

    public byte getMessageType() {
        return messageType;
    }

    public void setMessageType(byte messageType) {
        this.messageType = messageType;
    }

    public short getBizType() {
        return bizType;
    }

    public void setBizType(short bizType) {
        this.bizType = bizType;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public byte getCheck() {
        return check;
    }

    public void setCheck(byte check) {
        this.check = check;
    }

    @Override
    public String toString() {
        return "BaseFrame{" +
                "start=" + start +
                ", length=" + length +
                ", streamId=" + streamId +
                ", version=" + version +
                ", messageType=" + messageType +
                ", bizType=0x" + StringUtils.bytesToHexString(NumberUtils.shortToByte(bizType)) +
                ", body=" + Arrays.toString(body) +
                ", check=" + check +
                '}';
    }
}